package me.yushuai.wukong.base.convertor;

import me.yushuai.wukong.base.api.dto.CreatePackingDTO;
import me.yushuai.wukong.base.api.dto.PackingDTO;
import me.yushuai.wukong.base.api.dto.PackingUomDTO;
import me.yushuai.wukong.base.api.dto.UpdatePackingDTO;
import me.yushuai.wukong.base.api.vo.PackingVO;
import me.yushuai.wukong.base.entity.PackingBasic;
import me.yushuai.wukong.base.entity.PackingUom;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Mappings;

import java.util.List;

/**
 * @author zhoushuai@189.cn
 * @since 2022-11-22
 */
@Mapper(componentModel = "spring")
public interface PackingConvertor {

    @Mapping(target = "palletPackingId", ignore = true)
    @Mapping(target = "oprSeqFg", ignore = true)
    @Mapping(target = "modifyTime", ignore = true)
    @Mapping(target = "modifyBy", ignore = true)
    @Mapping(target = "innerPackingId", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "boxPackingId", ignore = true)
    @Mapping(target = "packingId", ignore = true)
    PackingBasic mapToPacking(CreatePackingDTO dto);

    @Mapping(target = "palletPackingId", ignore = true)
    @Mapping(target = "oprSeqFg", ignore = true)
    @Mapping(target = "modifyTime", ignore = true)
    @Mapping(target = "modifyBy", ignore = true)
    @Mapping(target = "innerPackingId", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "boxPackingId", ignore = true)
    @Mapping(target = "bizId", ignore = true)
    void updateToPacking(UpdatePackingDTO dto, @MappingTarget PackingBasic packingBasic);

    @Mapping(target = "sn3", ignore = true)
    @Mapping(target = "sn2", ignore = true)
    @Mapping(target = "sn1", ignore = true)
    @Mapping(target = "palletPackingUom", ignore = true)
    @Mapping(target = "oprseqfg", ignore = true)
    @Mapping(target = "innerPackingUom", ignore = true)
    @Mapping(target = "davr04", ignore = true)
    @Mapping(target = "davr03", ignore = true)
    @Mapping(target = "davr02", ignore = true)
    @Mapping(target = "davr01", ignore = true)
    @Mapping(target = "dain04", ignore = true)
    @Mapping(target = "dain03", ignore = true)
    @Mapping(target = "dain02", ignore = true)
    @Mapping(target = "dain01", ignore = true)
    @Mapping(target = "dafl04", ignore = true)
    @Mapping(target = "dafl03", ignore = true)
    @Mapping(target = "dafl02", ignore = true)
    @Mapping(target = "dafl01", ignore = true)
    @Mapping(target = "dadt04", ignore = true)
    @Mapping(target = "dadt03", ignore = true)
    @Mapping(target = "dadt02", ignore = true)
    @Mapping(target = "dadt01", ignore = true)
    @Mapping(target = "dadd04", ignore = true)
    @Mapping(target = "dadd03", ignore = true)
    @Mapping(target = "dadd02", ignore = true)
    @Mapping(target = "dadd01", ignore = true)
    @Mapping(target = "dach04", ignore = true)
    @Mapping(target = "dach03", ignore = true)
    @Mapping(target = "dach02", ignore = true)
    @Mapping(target = "dach01", ignore = true)
    @Mapping(target = "boxPackingUom", ignore = true)
    @Mapping(target = "packingUomList", source = "packingUomList")
    @Mapping(target = "basicUom", ignore = true)
    PackingDTO mapToPackingDto(PackingBasic packingBasic, List<PackingUom> packingUomList);


    @Mapping(target = "sn3", ignore = true)
    @Mapping(target = "sn2", ignore = true)
    @Mapping(target = "sn1", ignore = true)
    @Mapping(target = "palletPackingUom", ignore = true)
    @Mapping(target = "oprseqfg", ignore = true)
    @Mapping(target = "innerPackingUom", ignore = true)
    @Mapping(target = "davr04", ignore = true)
    @Mapping(target = "davr03", ignore = true)
    @Mapping(target = "davr02", ignore = true)
    @Mapping(target = "davr01", ignore = true)
    @Mapping(target = "dain04", ignore = true)
    @Mapping(target = "dain03", ignore = true)
    @Mapping(target = "dain02", ignore = true)
    @Mapping(target = "dain01", ignore = true)
    @Mapping(target = "dafl04", ignore = true)
    @Mapping(target = "dafl03", ignore = true)
    @Mapping(target = "dafl02", ignore = true)
    @Mapping(target = "dafl01", ignore = true)
    @Mapping(target = "dadt04", ignore = true)
    @Mapping(target = "dadt03", ignore = true)
    @Mapping(target = "dadt02", ignore = true)
    @Mapping(target = "dadt01", ignore = true)
    @Mapping(target = "dadd04", ignore = true)
    @Mapping(target = "dadd03", ignore = true)
    @Mapping(target = "dadd02", ignore = true)
    @Mapping(target = "dadd01", ignore = true)
    @Mapping(target = "dach04", ignore = true)
    @Mapping(target = "dach03", ignore = true)
    @Mapping(target = "dach02", ignore = true)
    @Mapping(target = "dach01", ignore = true)
    @Mapping(target = "boxPackingUom", ignore = true)
    @Mapping(target = "packingUomList", ignore = true)
    @Mapping(target = "basicUom", ignore = true)
    List<PackingDTO> mapToDtoList(List<PackingBasic> packingBasicList);

    @Mappings({
            @Mapping(source = "packingId", target = "packingId"),
            @Mapping(target = "basicUom", defaultValue = "true")
    })
    PackingUomDTO mapToUomDto(Long packingId, PackingUomDTO dto);

    @Mappings({
            @Mapping(source = "packingId", target = "packingId"),
            @Mapping(target = "basicUom", defaultValue = "true", ignore = true),
            @Mapping(target = "bizId", ignore = true),
            @Mapping(target = "cartonizeUom", ignore = true),
            @Mapping(target = "cubeUom", ignore = true),
            @Mapping(target = "heightUom", ignore = true),
            @Mapping(target = "inLabel", ignore = true),
            @Mapping(target = "lengthUom", ignore = true),
            @Mapping(target = "outLabel", ignore = true),
            @Mapping(target = "packMaterial", ignore = true),
            @Mapping(target = "qty", ignore = true),
            @Mapping(target = "uomId", ignore = true),
            @Mapping(target = "weightUom", ignore = true),
            @Mapping(target = "widthUom", ignore = true)
    })
    PackingUomDTO mapToPackingUomDto(Long packingId, UpdatePackingDTO dto);

    @Mapping(target = "basicUom", ignore = true)
    PackingUomDTO mapToPackingUomDto(PackingUom packingUom);

    @Mapping(target = "rplLabel", ignore = true)
    @Mapping(target = "basicUnit", ignore = true)
    PackingUom mapToPackingUom(PackingUomDTO dto);

    @Mapping(target = "rplLabel", ignore = true)
    @Mapping(target = "basicUnit", ignore = true)
    void updateToPackingUom(PackingUomDTO packingUomDTO, @MappingTarget PackingUom packingUom);

    PackingVO mapToPackingVo(PackingDTO packaging);

    List<PackingVO> mapToPackingVoList(List<PackingDTO> data);
}
